﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Demo
{
    public partial class Form21 : Form
    {
        Form2 form2;
        string[] str = new string[5];
        public Form21(Form2 f)
        {
            InitializeComponent();
            button3.Visible = false;
            form2 = f;
        }
        public Form21(string[] a,Form2 f)
        {
            form2 = f;
            InitializeComponent();
            for (int i = 0; i < 5; i++)
            { str[i] = a[i]; }
            textBox1.Text = str[0];
            textBox2.Text = str[1];
            textBox3.Text = str[2];
            textBox4.Text = str[3];
            textBox5.Text = str[4];
            textBox1.Text = str[0];
            button1.Visible = false;
        }
        //新建学生信息
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == ""|| textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "")
            { MessageBox.Show("输入不完整哟！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            else 
            { 
            string sql = "Insert into student values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','123456')";
            fengzhuang dao = new fengzhuang();
            int i = dao.Excute(sql);
            if (i > 0)
            {
                DialogResult r=MessageBox.Show("插入成功","恭喜发财",MessageBoxButtons.OK,MessageBoxIcon.Information);
                if (r == DialogResult.OK || r == DialogResult.Abort)
                { this.Close(); form2.Table(); }
            }

            }
        }
        //取消按钮
        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = null;
            textBox2.Text = null;
            textBox3.Text = null;
            textBox4.Text = null;
            textBox5.Text = null;
            this.Close();
        }
        //修改
        private void button3_Click(object sender, EventArgs e)
        {
            int flag = 0;
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "")
            { MessageBox.Show("您输入的信息不完整啊！", "可恶", MessageBoxButtons.OK, MessageBoxIcon.Question); }
            else {
                if (textBox1.Text != str[0])
                { string sql = "update student set id='"+textBox1.Text+"' where id='"+str[0]+"' and name='"+str[1]+"'";
                fengzhuang dao = new fengzhuang();
                dao.Excute(sql);
                str[0] = textBox1.Text;
                flag = 1;
                }
                if (textBox2.Text != str[1])
                {
                    string sql = "update student set name='" + textBox2.Text + "' where id='" + str[0] + "' and name='" + str[1] + "'";
                    fengzhuang dao = new fengzhuang();
                    dao.Excute(sql);
                    str[1] = textBox2.Text;
                    flag = 1;
                }
                if (textBox3.Text != str[2])
                {
                    string sql = "update student set class='" + textBox3.Text + "' where id='" + str[0] + "' and name='" + str[1] + "'";
                    fengzhuang dao = new fengzhuang();
                    dao.Excute(sql);
                    str[2] = textBox3.Text;
                    flag = 1;
                }
                if (textBox4.Text != str[3])
                {
                    string sql = "update student set birthday='" + textBox4.Text + "' where id='" + str[0] + "' and name='" + str[1] + "'";
                    fengzhuang dao = new fengzhuang();
                    dao.Excute(sql);
                    str[3] = textBox4.Text;
                    flag = 1;
                }
                if (textBox5.Text != str[4])
                {
                    string sql = "update student set jg='" + textBox5.Text + "' where id='" + str[0] + "' and name='" + str[1] + "'";
                    fengzhuang dao = new fengzhuang();
                    dao.Excute(sql);
                    str[4] = textBox5.Text;
                    flag = 1;
                }
                if (flag == 1)
                { DialogResult r=  MessageBox.Show("插入成功","tips",MessageBoxButtons.OK,MessageBoxIcon.Information);
                if (r == DialogResult.OK&&r==DialogResult.Abort)
                { this.Close(); form2.Table(); }
                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //禁止使用自定义颜色
            colorDialog1.AllowFullOpen = true;
            //提供自己给定的颜色
            colorDialog1.CustomColors = new int[] { 6916092, 15195440, 16107657, 1836924, 3758726, 12566463, 7526079, 7405793, 6945974, 241502, 2296476, 5130294, 3102017, 7324121, 14993507, 11730944 };
            colorDialog1.ShowHelp = true;
            colorDialog1.ShowDialog();
            this.BackColor = colorDialog1.Color;
        }

        private void Form21_Load(object sender, EventArgs e)
        {

        }





    }
}
